home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4152 < prev    next >
Encoding:
Text File  |  1996-08-06  |  2.0 KB  |  58 lines

  1. Path: news.th-darmstadt.de!news!enno
  2. From: enno@inferenzsysteme.informatik.th-darmstadt.de (Enno Sandner)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Need help with derived class template
  5. Date: 28 Jan 1996 13:43:58 GMT
  6. Organization: Fachbereich Informatik, TH Darmstadt
  7. Distribution: world
  8. Message-ID: <ENNO.96Jan28144358@kitz.inferenzsysteme.informatik.th-darmstadt.de>
  9. References: <4efbcv$ovo@agate.berkeley.edu>
  10. NNTP-Posting-Host: kitz.intellektik.informatik.th-darmstadt.de
  11. In-reply-to: parsons@vouvray.CS.Berkeley.EDU's message of 28 Jan 1996 08:16:31 GMT
  12.  
  13. In article <4efbcv$ovo@agate.berkeley.edu> parsons@vouvray.CS.Berkeley.EDU (David C. Parsons) writes:
  14.  
  15.    I am trying to write a class template which is derived from another
  16.    class template, and unfortunately can't seem to get the syntax right.
  17.    I've looked through the FAQ and my C++ books (Stroustrup, Lippman) and
  18.    can't find a discussion of this anywhere.
  19.  
  20.    The base class definition looks like this:
  21.  
  22.        template <class Type>
  23.        class Base { ... }
  24.  
  25.    The compile errors arise from the derived class definition.  Here are
  26.    the variations I've tried, and the errors they generate:
  27.  
  28.    1.      template <class Type>
  29.        class Derived : public Base { ... }
  30.  
  31.        ==> parse error before `{'
  32.  
  33.    2.      template <class Type>
  34.        class Derived : public Base<Type> { ... }
  35.  
  36.        ==> base class `Base<double>' has incomplete type
  37.  
  38.    3.      template <class Type>
  39.        class Derived<Type> : public Base<Type> { ... }
  40.  
  41.        ==> Internal compiler error.
  42.            Please submit a full bug report to `bug-g++@prep.ai.mit.edu'. 
  43.  
  44.    Any suggestions?  Incidentally, the base class by itself works fine,
  45.    and the inheritance works if I remove the templating (i.e. instantiate
  46.    it "by hand" to a particular type).
  47.  
  48. No. 2 is the correct syntax. For example the following snippet
  49.  
  50.     template<class Type> class Base {};
  51.     template<class Type> class Derived : public Base<Type> {};
  52.     int main() { Derived<int> d; return 0; }
  53.  
  54. should compile without any problems. So you have left out an
  55. important detail or your compiler is obsolete.
  56.  
  57.     Enno
  58.